<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            width: 200px;
            height: 200px;
            background-color: skyblue;
        }
    </style>
</head>
<body>
    <div>1</div>
    <br />
    <div>2</div>
    <br />
    <div>3</div>
    <script>
         /* 
            删除事件
                1. divs[0].onclick = null;
                2. divs[1].removeEventListener('click', fn);
        */
        var divs = document.querySelectorAll('div');
        divs[0].onclick = function () {
            console.log("传统方式注册");
            divs[0].onclick = null;
        }
        divs[1].addEventListener('click', fn);
        function fn() {
            console.log("监听器的方式注册事件");
            divs[1].removeEventListener('click', fn);
        }

        console.log('----------ie---------');
        // 3. detachEvent
        divs[2].attachEvent('onclick', fn1);

        function fn1() {
            alert(33);
            divs[2].detachEvent('onclick', fn1);
        }
    </script>
</body>
</html>